import {ListPage} from "custom/index";
import {getCustomerConsultationRecord, removeCustomerConsultationRecord} from '../api'
import {
    customerStatusOptions,
    followUpStatusOptions,
    customerSourceOptions,
    customerLvlOptions,
    quoteStatusOptiobs,
    endCooperation,
    archivingStatusOptions
} from '../constant'
import {addDialog, addRecordDialog, editDialog, masterDialog} from './dialog'
import {changeArchivingStatus, removeMaste} from './action'
import ContactJsonColumn from '@/components/table-column/ContactJsonColumn.vue'
import ImagesColumn from '@/components/table-column/ImagesColumn.vue'
import RateColumn from '@/components/table-column/RateColumn.vue'
import DrawerDetail from './components/DrawerDetail.vue'
import FavoriteColumn from './components/FavoriteColumn.vue'
import LinkColumn from "@/components/table-column/LinkColumn.vue";

const page = new ListPage('CustomerConsultationRecord');

page
    .api(getCustomerConsultationRecord)
    .useTabs()
    .setProp('searchStatus')
    .setDefualt('')
    .addTab({label: '全部', value: ''})
    .addTab({label: '今日新增', value: 1})
    .addTab({label: '本周新增', value: 2})
    .addTab({label: '我负责的', value: 3})
    .addTab({label: '我关注的', value: 4})
    .end()
    .useSearch()
    .addInputItem('keyword', '客户咨询记录 ', '')
    .addItem({prop: 'customerName', label: '客户名称'})
    .addItem({prop: 'masterName', label: '负责人'})
    .addSelect({prop: 'customerStatus', label: '客户状态'}, customerStatusOptions)
    .addSelect({prop: 'followUpStatus', label: '跟进状态'}, followUpStatusOptions)
    .addSelect({prop: 'customerSource', label: '客户来源'}, customerSourceOptions)
    .addSelect({prop: 'customerLvl', label: '客户分级'}, customerLvlOptions)
    .addDictSelect({prop: 'platformNo', label: '店铺平台'}, 'platform')
    .addSelect({props: 'quoteStatus', label: '报价状态'}, quoteStatusOptiobs)
    .addSelect({prop: 'endCooperation', label: '结束合作原因'}, endCooperation)
    .addDateTimeRangePicker(['createTimeStart', 'createTimeEnd'], {label: '创建时间'})
    .addDateTimeRangePicker(['updateTimeStart', 'updateTimeEnd'], {label: '更新时间'})
    .addSelect({prop: 'archivingStatus', label: '归档状态'}, archivingStatusOptions)
    .upto("ListPage")
    .add('PageTable')
    .useIndexColumn().end()
    .addColumn({prop: 'createTime', label: '创建时间', minWidth: 170})
    // .useDrawerColumn({prop: 'customerName', typeLink: 'link'}).label('客户名称').minWidth(180).end()
    .useDrawerColumn({prop: 'customerName', linkType: 'link'}).label('客户名称').minWidth(180).end()
    // .useCustomColumn(LinkColumn, { prop: 'shopName', linkProp: 'shopLinkUrl', linkType: 'link' }).label('店铺名称').minWidth(140).end()
    .addColumn({prop: 'masterName', label: '负责人', minWidth: 180})
    .useCustomColumn(ContactJsonColumn, 'contactJson').minWidth(180).label('客户联系方式').end()
    .addColumn({prop: 'customerStatus', label: '客户状态'})
    .addColumn({prop: 'followUpStatus', label: '跟进状态'})
    .addColumn({prop: 'customerSource', label: '客户来源', minWidth: 140})
    .addColumn({prop: 'customerLvl', label: '客户分级'})
    .addColumn({prop: 'platformName', label: '店铺平台'})
    .addColumn({prop: 'shopTypeName', label: '店铺经营类别', minWidth: 140})
    .addColumn({prop: 'quoteStatus', label: '报价状态'})
    .addColumn({prop: 'feeType', label: '收费模式'})
    .addColumn({prop: 'feeAmount', label: '收费金额', align: 'center'})
    .addCustomColumn(RateColumn, {prop: 'importanceLevel', label: '重要程度', minWidth: 140})
    .addColumn({prop: 'shopLinkUrl', label: '店铺链接', minWidth: 180})
    .addColumn({prop: 'businessAnalysis', label: '商机分析'})
    .addColumn({prop: 'customerDemand', label: '客户需求'})
    .addCustomColumn(ImagesColumn, {prop: 'chatHistory', label: '聊天记录'})
    .addColumn({prop: 'remark', label: '备注', minWidth: 250})
    .addColumn({prop: 'createUserName', label: '创建人'})
    .addColumn({prop: 'updateTime', label: '更新时间', minWidth: 170})
    .addColumn({prop: 'endCooperation', label: '结束合作原因', minWidth: 150})
    .addCustomColumn(FavoriteColumn, {prop: 'favoriteStatus', label: '关注'})
    .addColumn({
        prop: 'archivingStatus',
        label: '归档状态',
        formatter: row => row.archivingStatus ? '已归档' : '未归档'
    })
    .upto('ListPage')
    .add('PagePagination')
    .end()
    .useAuthButton()
    .useItem('add').content('新增').primary().addRow(addDialog).end()
    .useItem('export').content('导出数据').exportExcel().end()
    .end()
    .useAuthColumn({width: 440})
    .useItem('edit').content('编辑').editRow(editDialog).end()
    .useItem('edit').content('添加跟进记录').editRow(addRecordDialog).end()
    .useItem('file').formatter(row => row.archivingStatus ? '取消归档' : '归档').action(changeArchivingStatus).end()
    .useItem('delete').content('删除').removeRow(removeCustomerConsultationRecord, row => [row.consultId]).end()
    .useItem('transfer').content('移交').editRow(masterDialog).end()
    .useItem('deleteperson').content('删除负责人').action(removeMaste).end()
    .upto('ListPage')
    .useDrawer()
    .setComponent(DrawerDetail)

export default page
